package com.atjinggu.jinggumail.order.web;

import com.atjinggu.jinggumail.common.constant.AuthConstant;
import com.atjinggu.jinggumail.order.entity.OrderEntity;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jingming
 * @Type HelloController.java
 * @Desc
 * @date 2021/3/7 19:12
 */
@Controller
public class HelloController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @ResponseBody
    @GetMapping("/{page}.html")
    public String listPage(@PathVariable("page") String page, HttpServletRequest request, HttpServletResponse response)
    {
        request.getSession().getAttribute(AuthConstant.LOGIN_USER);
        System.out.println(request.getSession().getId());
        return page;
    }

    @GetMapping("/send")
    public String send(){
        OrderEntity entity = new OrderEntity();
        entity.setOrderSn("jmmmmmmmmm");
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",entity);
        return "ok";
    }
}